/**
 * 冲泡方式管理初始化
 */
var Brews = {
    id: "BrewsTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Brews.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: 'id', field: 'id', visible: true, align: 'center', valign: 'middle'},
        {title: '名称', field: 'name', visible: true, align: 'center', valign: 'middle'},
        {title: '适宜容器', field: 'teapot', visible: true, align: 'center', valign: 'middle'},
        {title: '适宜温度', field: 'temperature', visible: true, align: 'center', valign: 'middle'},
        {title: '茶水比例', field: 'percent', visible: true, align: 'center', valign: 'middle'},
        // {title: '详情', field: 'details', visible: true, align: 'center', valign: 'middle'},
        //{title: '状态', field: 'status', visible: true, align: 'center', valign: 'middle'},
        // {title: '', field: 'crtUser', visible: true, align: 'center', valign: 'middle'},
        // {title: '', field: 'crtTime', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
Brews.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        Brews.seItem = selected[0];
        return true;
    }
};
/**
 * 点击添加冲泡方式
 */
Brews.openAddBrews = function () {
    var index = layer.open({
        type: 2,
        title: '添加冲泡方式',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/brews/brews_add'
    });
    this.layerIndex = index;
    layer.full(index);
};

/**
 * 打开查看冲泡方式详情
 */
Brews.openBrewsDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '冲泡方式详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/brews/brews_update/' + Brews.seItem.id
        });
        this.layerIndex = index;
        layer.full(index);
    }
};

/**
 * 删除冲泡方式
 */
Brews.delete = function () {
    if (this.check()) {
        // 遍历删除选中记录
        var operation = function () {
            var ajax = new $ax(Feng.ctxPath + "/brews/delete", function (data) {
                Feng.success("删除成功!您还可以在回收站恢复该信息");
                Brews.table.refresh();
            }, function (data) {
                Feng.error("删除失败!" + data.responseJSON.message + "!");
            });
            ajax.set("brewsId", Brews.seItem.id);
            ajax.set("brewsName", Brews.seItem.name);
            ajax.start();
        };
        Feng.confirm("是否删除选中的冲泡方式?", operation);
    }
};

/**
 * 查询冲泡方式列表
 */
Brews.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    Brews.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = Brews.initColumn();
    var table = new BSTable(Brews.id, "/brews/list", defaultColunms);
    table.setPaginationType("client");
    Brews.table = table.init();
});
